﻿using IterationLife.ContentResources.Models;
using Util.Datas.Ef;

namespace IterationLife.Datas.Mappings.ContentResources {
    /// <summary>
    /// 内容资源映射配置
    /// </summary>
    public class ContentResourceMap : AggregateRootMapBase<ContentResource> {
        /// <summary>
        /// 映射表
        /// </summary>
        protected override void MapTable() {
            ToTable( "ContentResources", "Commons" );
        }
        
        /// <summary>
        /// 映射属性
        /// </summary>
        protected override void MapProperties() {
            //内容资源编号
            Property(t => t.Id)
                .HasColumnName("ContentResourceId");
            //单封面图
            Property(t => t.SingleBannerJsonStr)
                .HasColumnName("SingleBanner");
            //多封面图集合
            Property(t => t.MultiBannersJsonStr)
                .HasColumnName("MultiBanners");
            //系统封面图集合
            Property(t => t.SystemBannersJsonStr)
                .HasColumnName("SystemBanners");
            //视频
            Property(t => t.VideoJsonStr)
                .HasColumnName("Video");
        }
        
        /// <summary>
        /// 映射导航属性
        /// </summary>
        protected override void MapAssociations() {
            //内容资源分类
            HasOptional(t => t.CategoriyContentResourceCategory)
                .WithMany(t => t.CategoriyContentResources)
                .HasForeignKey(d => d.CategoriyId);
        }
    }
}